package com.ruoyi.common.exception;

import com.ruoyi.common.core.result.Result;
import lombok.Getter;

/**
 * 业务异常
 *
 * @author ruoyi
 */
@Getter
public final class ServiceException extends RuntimeException {

    private static final long serialVersionUID = -1858982528597473173L;
    private final Result<Void> errorResult;

    /**
     * 空构造方法，避免反序列化问题
     */
    public ServiceException() {
        super(Result.error().getMsg());
        errorResult = Result.error();
    }

    public ServiceException(String message) {
        super(message);
        errorResult = Result.error(message);
    }

    public ServiceException(String message, Integer code) {
        super(message);
        errorResult = Result.error(code, message);
    }

    public ServiceException(Result<Void> errorResult) {
        super(errorResult.getMsg());
        this.errorResult = errorResult;
    }

    @Override
    public String getMessage() {
        return errorResult.getMsg();
    }
}
